package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.IMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class IMController {

    @Autowired
    private IMService imService;

    /**
     * 添加联系人
     *
     * @param paramMap
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity addContacts(@RequestBody Map<String, Long> paramMap) {
        imService.addContacts(paramMap);
        return ResponseEntity.ok(null);
    }

    /**
     * 联系人分页查询
     *
     * @param page
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity contactList(@RequestParam(value = "page", defaultValue = "1") Long page,
                                      @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize,
                                      @RequestParam(value = "keyword", required = false) String keyword) {
        PageResult pageResult = imService.contactList(page, pageSize, keyword);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 谁点赞了我的列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/likes")
    public ResponseEntity likesList(@RequestParam(value = "page", defaultValue = "1") Long page,
                                    @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize) {
        ////评论类型，1-点赞，2-评论，3-喜欢
        PageResult pageResult = imService.messageCommentList(1, page,pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 谁喜欢了我的列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/loves")
    public ResponseEntity lovesList(@RequestParam(value = "page", defaultValue = "1") Long page,
                                    @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize) {
        ////评论类型，1-点赞，2-评论，3-喜欢
        PageResult pageResult = imService.messageCommentList(3, page,pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 谁评论了我的列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/comments")
    public ResponseEntity commentsList(@RequestParam(value = "page", defaultValue = "1") Long page,
                                    @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize) {
        //评论类型，1-点赞，2-评论，3-喜欢
        PageResult pageResult = imService.messageCommentList(2, page,pageSize);
        return ResponseEntity.ok(pageResult);
    }
}
